package com.gmail.dmitryustimov.ms.java7.observer.mod.demo.subj1subsc10event10;

import com.gmail.dmitryustimov.ms.java7.patternslib.observer.SubscriberAction;

import java.math.BigDecimal;

public class Subscriber {

    private String name;
    private Subject subject;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public Subscriber(Subject subject, String name) {
        this.name = name;
        this.subject = subject;
        this.subject.getEvent1Publisher().subscribe(this.new Event1Action());
        this.subject.getEvent2Publisher().subscribe(this.new Event2Action());
        this.subject.getEvent3Publisher().subscribe(this.new Event3Action());
        this.subject.getEvent4Publisher().subscribe(this.new Event4Action());
        this.subject.getEvent5Publisher().subscribe(this.new Event5Action());
        this.subject.getEvent6Publisher().subscribe(this.new Event6Action());
        this.subject.getEvent7Publisher().subscribe(this.new Event7Action());
        this.subject.getEvent8Publisher().subscribe(this.new Event8Action());
        this.subject.getEvent9Publisher().subscribe(this.new Event9Action());
        this.subject.getEvent10Publisher().subscribe(this.new Event10Action());
    }

    private class Event1Action implements SubscriberAction<Event1> {
        @Override
        public void process(Event1 event) {
            sum.add(BigDecimal.valueOf(1));
        }
    }

    private class Event2Action implements SubscriberAction<Event2> {
        @Override
        public void process(Event2 event) {
            sum.add(BigDecimal.valueOf(2));
        }
    }

    private class Event3Action implements SubscriberAction<Event3> {
        @Override
        public void process(Event3 event) {
            sum.add(BigDecimal.valueOf(3));
        }
    }

    private class Event4Action implements SubscriberAction<Event4> {
        @Override
        public void process(Event4 event) {
            sum.add(BigDecimal.valueOf(4));
        }
    }

    private class Event5Action implements SubscriberAction<Event5> {
        @Override
        public void process(Event5 event) {
            sum.add(BigDecimal.valueOf(5));
        }
    }

    private class Event6Action implements SubscriberAction<Event6> {
        @Override
        public void process(Event6 event) {
            sum.add(BigDecimal.valueOf(6));
        }
    }

    private class Event7Action implements SubscriberAction<Event7> {
        @Override
        public void process(Event7 event) {
            sum.add(BigDecimal.valueOf(7));
        }
    }

    private class Event8Action implements SubscriberAction<Event8> {
        @Override
        public void process(Event8 event) {
            sum.add(BigDecimal.valueOf(8));
        }
    }

    private class Event9Action implements SubscriberAction<Event9> {
        @Override
        public void process(Event9 event) {
            sum.add(BigDecimal.valueOf(9));
        }
    }

    private class Event10Action implements SubscriberAction<Event10> {
        @Override
        public void process(Event10 event) {
            sum.add(BigDecimal.valueOf(10));
        }
    }
}
